//
//  RHMeOrgnizationListCell.m
//  RuiHeApp
//
//  Created by Yan Chen on 2025/1/20.
//

#import "RHMeOrgnizationListCell.h"
#import "RHMeOrgnizationModel.h"
@interface RHMeOrgnizationListCell()

@property(nonatomic, strong) QMUIButton *selectBtn;

@property(nonatomic, strong) UIImageView *orgIcon;

@property(nonatomic, strong) QMUILabel *orgNameLab;

@property(nonatomic, strong) UIImageView *arrowImg;

@end
@implementation RHMeOrgnizationListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}

-(void)showArrow:(BOOL)isShow
{
    self.arrowImg.hidden = !isShow;
}

-(void)setOrgModel:(RHMeOrgnizationModel *)orgModel
{
    _orgModel = orgModel;
    self.orgNameLab.text = orgModel.orgName;
    self.selectBtn.selected = orgModel.isSelected;
    
}

- (void)setupUI{
    kWeakSelf;
    [self setBackgroundColor:UIColor.clearColor];
    [self.contentView setBackgroundColor:UIColor.clearColor];
    
    UIView *containView = [[UIView alloc]init];
    [self.contentView addSubview:containView];
    containView.backgroundColor = [UIColor whiteColor];
    [containView rounded:8 width:1 color:kBorderColor];
    [containView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(5, 10, 5, 10));
        make.height.offset(64);
    }];
    
    _selectBtn = [[QMUIButton alloc]init];
    [_selectBtn setImage:[UIImage imageNamed:@"org_normal_icon"] forState:UIControlStateNormal];
    [_selectBtn setImage:[UIImage imageNamed:@"org_selected_icon"] forState:UIControlStateSelected];
    _selectBtn.contentMode = UIViewContentModeScaleAspectFill;
    [containView addSubview:_selectBtn];
    [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(5);
        make.width.height.offset(30);
        make.centerY.mas_offset(0);
    }];
    
    
    _orgIcon = [[UIImageView alloc]init];
    [_orgIcon setImage:[UIImage imageNamed:@"org_icon"]];
    _orgIcon.contentMode = UIViewContentModeScaleAspectFill;
    [containView addSubview:_orgIcon];
    [_orgIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.selectBtn.mas_right).offset(0);
            make.width.height.offset(34);
            make.centerY.mas_offset(0);
    }];
    
    _arrowImg = [[UIImageView alloc]init];
    [containView addSubview:_arrowImg];
    [_arrowImg setImage:[UIImage imageNamed:@"arrow"]];
    [_arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(15);
        make.right.mas_offset(-15);
        make.centerY.mas_offset(0);
    }];
    
    _orgNameLab = [QMUILabel labelWithFont:kSYSTEMFONT(14) textColor:kCOLOR_HEX(@"#303133") textAligment:NSTextAlignmentLeft];
    [containView addSubview:_orgNameLab];
    [_orgNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.orgIcon.mas_right).offset(5);
        make.centerY.mas_offset(0);
        make.right.equalTo(weakSelf.arrowImg.mas_left).offset(-3);
    }];

   
    [[_selectBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (weakSelf.selectBlock) {
            weakSelf.selectBlock(weakSelf.orgModel);
        }
    }];
    
}

@end
